home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2002 November / CD 1 / APC0211D1.ISO / workshop / prog / files / ActivePerl-5.6.1.633-MSWin32.msi / _27931c6b74ed0d7d384415553f770f63 < prev    next >
Encoding:
Text File  |  2002-06-17  |  23.7 KB  |  863 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15.     eval 'exec C:\p4view\Apps\ActivePerl\MSI\data\ActivePerl\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  16.       if $running_under_some_shell;
  17. (my $perlpath = <<'/../') =~ s/\s*\z//;
  18. C:\p4view\Apps\ActivePerl\MSI\data\ActivePerl\Perl\bin\perl.exe
  19. /../
  20. use strict;
  21. use vars qw/$statdone/;
  22. use File::Spec::Functions 'curdir';
  23. my $startperl = "#! $perlpath -w";
  24.  
  25. #
  26. # Modified September 26, 1993 to provide proper handling of years after 1999
  27. #   Tom Link <tml+@pitt.edu>
  28. #   University of Pittsburgh
  29. #
  30. # Modified April 7, 1998 with nasty hacks to implement the troublesome -follow
  31. #  Billy Constantine <wdconsta@cs.adelaide.edu.au> <billy@smug.adelaide.edu.au>
  32. #  University of Adelaide, Adelaide, South Australia
  33. #
  34. # Modified 1999-06-10, 1999-07-07 to migrate to cleaner perl5 usage
  35. #   Ken Pizzini <ken@halcyon.com>
  36. #
  37. # Modified 2000-01-28 to use the 'follow' option of File::Find
  38.  
  39. my @roots = ();
  40. while ($ARGV[0] =~ /^[^-!(]/) {
  41.     push(@roots, shift);
  42. }
  43. @roots = (curdir()) unless @roots;
  44. for (@roots) { $_ = "e($_) }
  45. my $roots = join(', ', @roots);
  46.  
  47. my $find = "find";
  48. my $indent_depth = 1;
  49. my $stat = 'lstat';
  50. my $decl = '';
  51. my $flushall = '';
  52. my $initfile = '';
  53. my $initnewer = '';
  54. my $out = '';
  55. my %init = ();
  56. my ($follow_in_effect,$Skip_And) = (0,0);
  57.  
  58. while (@ARGV) {
  59.     $_ = shift;
  60.     s/^-// || /^[()!]/ || die "Unrecognized switch: $_\n";
  61.     if ($_ eq '(') {
  62.         $out .= &tab . "(\n";
  63.         $indent_depth++;
  64.         next;
  65.     } elsif ($_ eq ')') {
  66.         --$indent_depth;
  67.         $out .= &tab . ")";
  68.     } elsif ($_ eq 'follow') {
  69.         $follow_in_effect= 1;
  70.         $stat = 'stat';
  71.         $Skip_And= 1;
  72.     } elsif ($_ eq '!') {
  73.         $out .= &tab . "!";
  74.         next;
  75.     } elsif ($_ eq 'name') {
  76.         $out .= &tab . '/' . &fileglob_to_re(shift) . "/s";
  77.     } elsif ($_ eq 'perm') {
  78.         my $onum = shift;
  79.         $onum =~ /^-?[0-7]+$/
  80.             || die "Malformed -perm argument: $onum\n";
  81.         $out .= &tab;
  82.         if ($onum =~ s/^-//) {
  83.             $onum = sprintf("0%o", oct($onum) & 07777);
  84.             $out .= "((\$mode & $onum) == $onum)";
  85.         } else {
  86.             $onum =~ s/^0*/0/;
  87.             $out .= "((\$mode & 0777) == $onum)";
  88.         }
  89.     } elsif ($_ eq 'type') {
  90.         (my $filetest = shift) =~ tr/s/S/;
  91.         $out .= &tab . "-$filetest _";
  92.     } elsif ($_ eq 'print') {
  93.         $out .= &tab . 'print("$name\n")';
  94.     } elsif ($_ eq 'print0') {
  95.         $out .= &tab . 'print("$name\0")';
  96.     } elsif ($_ eq 'fstype') {
  97.         my $type = shift;
  98.         $out .= &tab;
  99.         if ($type eq 'nfs') {
  100.             $out .= '($dev < 0)';
  101.         } else {
  102.             $out .= '($dev >= 0)'; #XXX
  103.         }
  104.     } elsif ($_ eq 'user') {
  105.         my $uname = shift;
  106.         $out .= &tab . "(\$uid == \$uid{'$uname'})";
  107.         $init{user} = 1;
  108.     } elsif ($_ eq 'group') {
  109.         my $gname = shift;
  110.         $out .= &tab . "(\$gid == \$gid{'$gname'})";
  111.         $init{group} = 1;
  112.     } elsif ($_ eq 'nouser') {
  113.         $out .= &tab . '!exists $uid{$uid}';
  114.         $init{user} = 1;
  115.     } elsif ($_ eq 'nogroup') {
  116.         $out .= &tab . '!exists $gid{$gid}';
  117.         $init{group} = 1;
  118.     } elsif ($_ eq 'links') {
  119.         $out .= &tab . &n('$nlink', shift);
  120.     } elsif ($_ eq 'inum') {
  121.         $out .= &tab . &n('$ino', shift);
  122.     } elsif ($_ eq 'size') {
  123.         $_ = shift;
  124.         my $n = 'int(((-s _) + 511) / 512)';
  125.         if (s/c\z//) {
  126.             $n = 'int(-s _)';
  127.         } elsif (s/k\z//) {
  128.             $n = 'int(((-s _) + 1023) / 1024)';
  129.         }
  130.         $out .= &tab . &n($n, $_);
  131.     } elsif ($_ eq 'atime') {
  132.         $out .= &tab . &n('int(-A _)', shift);
  133.     } elsif ($_ eq 'mtime') {
  134.         $out .= &tab . &n('int(-M _)', shift);
  135.     } elsif ($_ eq 'ctime') {
  136.         $out .= &tab . &n('int(-C _)', shift);
  137.     } elsif ($_ eq 'exec') {
  138.         my @cmd = ();
  139.         while (@ARGV && $ARGV[0] ne ';')
  140.             { push(@cmd, shift) }
  141.         shift;
  142.         $out .= &tab;
  143.         if ($cmd[0] =~m#^(?:(?:/usr)?/bin/)?rm$#
  144.                 && $cmd[$#cmd] eq '{}'
  145.                 && (@cmd == 2 || (@cmd == 3 && $cmd[1] eq '-f'))) {
  146.             if (@cmd == 2) {
  147.                 $out .= '(unlink($_) || warn "$name: $!\n")';
  148.             } elsif (!@ARGV) {
  149.                 $out .= 'unlink($_)';
  150.             } else {
  151.                 $out .= '(unlink($_) || 1)';
  152.             }
  153.         } else {
  154.             for (@cmd)
  155.                 { s/'/\\'/g }
  156.             { local $" = "','"; $out .= "&doexec(0, '@cmd')"; }
  157.             $init{doexec} = 1;
  158.         }
  159.     } elsif ($_ eq 'ok') {
  160.         my @cmd = ();
  161.         while (@ARGV && $ARGV[0] ne ';')
  162.             { push(@cmd, shift) }
  163.         shift;
  164.         $out .= &tab;
  165.         for (@cmd)
  166.             { s/'/\\'/g }
  167.         { local $" = "','"; $out .= "&doexec(0, '@cmd')"; }
  168.         $init{doexec} = 1;
  169.     } elsif ($_ eq 'prune') {
  170.         $out .= &tab . '($File::Find::prune = 1)';
  171.     } elsif ($_ eq 'xdev') {
  172.         $out .= &tab . '!($File::Find::prune |= ($dev != $File::Find::topdev))'
  173. ;
  174.     } elsif ($_ eq 'newer') {
  175.         my $file = shift;
  176.         my $newername = 'AGE_OF' . $file;
  177.         $newername =~ s/\W/_/g;
  178.         $newername = '$' . $newername;
  179.         $out .= &tab . "(-M _ < $newername)";
  180.         $initnewer .= "my $newername = -M " . "e($file) . ";\n";
  181.     } elsif ($_ eq 'eval') {
  182.         my $prog = shift;
  183.         $prog =~ s/'/\\'/g;
  184.         $out .= &tab . "eval {$prog}";
  185.     } elsif ($_ eq 'depth') {
  186.         $find = 'finddepth';
  187.         next;
  188.     } elsif ($_ eq 'ls') {
  189.         $out .= &tab . "&ls";
  190.         $init{ls} = 1;
  191.     } elsif ($_ eq 'tar') {
  192.         die "-tar must have a filename argument\n" unless @ARGV;
  193.         my $file = shift;
  194.         my $fh = 'FH' . $file;
  195.         $fh =~ s/\W/_/g;
  196.         $out .= &tab . "&tar(*$fh, \$name)";
  197.         $flushall .= "&tflushall;\n";
  198.         $initfile .= "open($fh, " . "e('> ' . $file) .
  199.                      qq{) || die "Can't open $fh: \$!\\n";\n};
  200.         $init{tar} = 1;
  201.     } elsif (/^(n?)cpio\z/) {
  202.         die "-$_ must have a filename argument\n" unless @ARGV;
  203.         my $file = shift;
  204.         my $fh = 'FH' . $file;
  205.         $fh =~ s/\W/_/g;
  206.         $out .= &tab . "&cpio(*$fh, \$name, '$1')";
  207.         $find = 'finddepth';
  208.         $flushall .= "&cflushall;\n";
  209.         $initfile .= "open($fh, " . "e('> ' . $file) .
  210.                      qq{) || die "Can't open $fh: \$!\\n";\n};
  211.         $init{cpio} = 1;
  212.     } else {
  213.         die "Unrecognized switch: -$_\n";
  214.     }
  215.  
  216.     if (@ARGV) {
  217.         if ($ARGV[0] eq '-o') {
  218.             { local($statdone) = 1; $out .= "\n" . &tab . "||\n"; }
  219.             $statdone = 0 if $indent_depth == 1 && exists $init{delayedstat};
  220.             $init{saw_or} = 1;
  221.             shift;
  222.         } else {
  223.             $out .= " &&" unless $Skip_And || $ARGV[0] eq ')';
  224.             $out .= "\n";
  225.             shift if $ARGV[0] eq '-a';
  226.         }
  227.     }
  228. }
  229.  
  230.  
  231. print <<"END";
  232. $startperl
  233.     eval 'exec $perlpath -S \$0 \${1+"\$@"}'
  234.         if 0; #\$running_under_some_shell
  235.  
  236. use strict;
  237. use File::Find ();
  238.  
  239. # Set the variable \$File::Find::dont_use_nlink if you're using AFS,
  240. # since AFS cheats.
  241.  
  242. # for the convenience of &wanted calls, including -eval statements:
  243. use vars qw/*name *dir *prune/;
  244. *name   = *File::Find::name;
  245. *dir    = *File::Find::dir;
  246. *prune  = *File::Find::prune;
  247.  
  248. END
  249.  
  250.  
  251. if (exists $init{ls}) {
  252.     print <<'END';
  253. my @rwx = qw(--- --x -w- -wx r-- r-x rw- rwx);
  254. my @moname = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
  255.  
  256. END
  257. }
  258.  
  259. if (exists $init{user} || exists $init{ls} || exists $init{tar}) {
  260.     print "my (%uid, %user);\n";
  261.     print "while (my (\$name, \$pw, \$uid) = getpwent) {\n";
  262.     print '    $uid{$name} = $uid{$uid} = $uid;', "\n"
  263.         if exists $init{user};
  264.     print '    $user{$uid} = $name unless exists $user{$uid};', "\n"
  265.         if exists $init{ls} || exists $init{tar};
  266.     print "}\n\n";
  267. }
  268.  
  269. if (exists $init{group} || exists $init{ls} || exists $init{tar}) {
  270.     print "my (%gid, %group);\n";
  271.     print "while (my (\$name, \$pw, \$gid) = getgrent) {\n";
  272.     print '    $gid{$name} = $gid{$gid} = $gid;', "\n"
  273.         if exists $init{group};
  274.     print '    $group{$gid} = $name unless exists $group{$gid};', "\n"
  275.         if exists $init{ls} || exists $init{tar};
  276.     print "}\n\n";
  277. }
  278.  
  279. print $initnewer, "\n" if $initnewer ne '';
  280. print $initfile, "\n" if $initfile ne '';
  281. $flushall .= "exit;\n";
  282. if (exists $init{declarestat}) {
  283.     $out = <<'END' . $out;
  284.     my ($dev,$ino,$mode,$nlink,$uid,$gid);
  285.  
  286. END
  287. }
  288.  
  289. if ( $follow_in_effect ) {
  290. $out =~ s/lstat\(\$_\)/lstat(_)/;
  291. print <<"END";
  292. $decl
  293. # Traverse desired filesystems
  294. File::Find::$find( {wanted => \\&wanted, follow => 1}, $roots);
  295. $flushall
  296.  
  297. sub wanted {
  298. $out;
  299. }
  300.  
  301. END
  302. } else {
  303. print <<"END";
  304. $decl
  305. # Traverse desired filesystems
  306. File::Find::$find({wanted => \\&wanted}, $roots);
  307. $flushall
  308.  
  309. sub wanted {
  310. $out;
  311. }
  312.  
  313. END
  314. }
  315.  
  316. if (exists $init{doexec}) {
  317.     print <<'END';
  318.  
  319. use Cwd ();
  320. my $cwd = Cwd::cwd();
  321.  
  322. sub doexec {
  323.     my $ok = shift;
  324.     for my $word (@_)
  325.         { $word =~ s#{}#$name#g }
  326.     if ($ok) {
  327.         my $old = select(STDOUT);
  328.         $| = 1;
  329.         print "@_";
  330.         select($old);
  331.         return 0 unless <STDIN> =~ /^y/;
  332.     }
  333.     chdir $cwd; #sigh
  334.     system @_;
  335.     chdir $File::Find::dir;
  336.     return !$?;
  337. }
  338.  
  339. END
  340. }
  341.  
  342. if (exists $init{ls}) {
  343.     print <<'INTRO', <<"SUB", <<'END';
  344.  
  345. sub sizemm {
  346.     my $rdev = shift;
  347.     sprintf("%3d, %3d", ($rdev >> 8) & 0xff, $rdev & 0xff);
  348. }
  349.  
  350. sub ls {
  351.     my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  352. INTRO
  353.         \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
  354. SUB
  355.     my $pname = $name;
  356.  
  357.     $blocks
  358.         or $blocks = int(($size + 1023) / 1024);
  359.  
  360.     my $perms = $rwx[$mode & 7];
  361.     $mode >>= 3;
  362.     $perms = $rwx[$mode & 7] . $perms;
  363.     $mode >>= 3;
  364.     $perms = $rwx[$mode & 7] . $perms;
  365.     substr($perms, 2, 1) =~ tr/-x/Ss/ if -u _;
  366.     substr($perms, 5, 1) =~ tr/-x/Ss/ if -g _;
  367.     substr($perms, 8, 1) =~ tr/-x/Tt/ if -k _;
  368.     if    (-f _) { $perms = '-' . $perms; }
  369.     elsif (-d _) { $perms = 'd' . $perms; }
  370.     elsif (-l _) { $perms = 'l' . $perms; $pname .= ' -> ' . readlink($_); }
  371.     elsif (-c _) { $perms = 'c' . $perms; $size = sizemm($rdev); }
  372.     elsif (-b _) { $perms = 'b' . $perms; $size = sizemm($rdev); }
  373.     elsif (-p _) { $perms = 'p' . $perms; }
  374.     elsif (-S _) { $perms = 's' . $perms; }
  375.     else         { $perms = '?' . $perms; }
  376.  
  377.     my $user = $user{$uid} || $uid;
  378.     my $group = $group{$gid} || $gid;
  379.  
  380.     my ($sec,$min,$hour,$mday,$mon,$timeyear) = localtime($mtime);
  381.     if (-M _ > 365.25 / 2) {
  382.         $timeyear += 1900;
  383.     } else {
  384.         $timeyear = sprintf("%02d:%02d", $hour, $min);
  385.     }
  386.  
  387.     printf "%5lu %4ld %-10s %3d %-8s %-8s %8s %s %2d %5s %s\n",
  388.             $ino,
  389.                  $blocks,
  390.                       $perms,
  391.                             $nlink,
  392.                                 $user,
  393.                                      $group,
  394.                                           $size,
  395.                                               $moname[$mon],
  396.                                                  $mday,
  397.                                                      $timeyear,
  398.                                                          $pname;
  399.     1;
  400. }
  401.  
  402. END
  403. }
  404.  
  405.  
  406. if (exists $init{cpio} || exists $init{tar}) {
  407. print <<'END';
  408.  
  409. my %blocks = ();
  410.  
  411. sub flush {
  412.     my ($fh, $varref, $blksz) = @_;
  413.  
  414.     while (length($$varref) >= $blksz) {
  415.         no strict qw/refs/;
  416.         syswrite($fh, $$varref, $blksz);
  417.         substr($$varref, 0, $blksz) = '';
  418.         ++$blocks{$fh};
  419.     }
  420. }
  421.  
  422. END
  423. }
  424.  
  425.  
  426. if (exists $init{cpio}) {
  427.     print <<'INTRO', <<"SUB", <<'END';
  428.  
  429. my %cpout = ();
  430. my %nc = ();
  431.  
  432. sub cpio {
  433.     my ($fh, $fname, $nc) = @_;
  434.     my $text = '';
  435.     my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  436.         $atime,$mtime,$ctime,$blksize,$blocks);
  437.     local (*IN);
  438.  
  439.     if ( ! defined $fname ) {
  440.         $fname = 'TRAILER!!!';
  441.         ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  442.           $atime,$mtime,$ctime,$blksize,$blocks) = (0) x 13;
  443.     } else {
  444.         ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  445. INTRO
  446.           \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
  447. SUB
  448.         if (-f _) {
  449.             open(IN, "./$_\0") || do {
  450.                 warn "Couldn't open $fname: $!\n";
  451.                 return;
  452.             }
  453.         } else {
  454.             $text = readlink($_);
  455.             $size = 0 unless defined $text;
  456.         }
  457.     }
  458.  
  459.     $fname =~ s#^\./##;
  460.     $nc{$fh} = $nc;
  461.     if ($nc eq 'n') {
  462.         $cpout{$fh} .=
  463.           sprintf("%06o%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo%s\0",
  464.             070707,
  465.             $dev & 0777777,
  466.             $ino & 0777777,
  467.             $mode & 0777777,
  468.             $uid & 0777777,
  469.             $gid & 0777777,
  470.             $nlink & 0777777,
  471.             $rdev & 0177777,
  472.             $mtime,
  473.             length($fname)+1,
  474.             $size,
  475.             $fname);
  476.     } else {
  477.         $cpout{$fh} .= "\0" if length($cpout{$fh}) & 1;
  478.         $cpout{$fh} .= pack("SSSSSSSSLSLa*",
  479.             070707, $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime,
  480.             length($fname)+1, $size,
  481.             $fname . (length($fname) & 1 ? "\0" : "\0\0"));
  482.     }
  483.  
  484.     if ($text ne '') {
  485.         $cpout{$fh} .= $text;
  486.     } elsif ($size) {
  487.         my $l;
  488.         flush($fh, \$cpout{$fh}, 5120)
  489.             while ($l = length($cpout{$fh})) >= 5120;
  490.         while (sysread(IN, $cpout{$fh}, 5120 - $l, $l)) {
  491.             flush($fh, \$cpout{$fh}, 5120);
  492.             $l = length($cpout{$fh});
  493.         }
  494.         close IN;
  495.     }
  496. }
  497.  
  498. sub cflushall {
  499.     for my $fh (keys %cpout) {
  500.         &cpio($fh, undef, $nc{$fh});
  501.         $cpout{$fh} .= "0" x (5120 - length($cpout{$fh}));
  502.         flush($fh, \$cpout{$fh}, 5120);
  503.         print $blocks{$fh} * 10, " blocks\n";
  504.     }
  505. }
  506.  
  507. END
  508. }
  509.  
  510. if (exists $init{tar}) {
  511.     print <<'INTRO', <<"SUB", <<'END';
  512.  
  513. my %tarout = ();
  514. my %linkseen = ();
  515.  
  516. sub tar {
  517.     my ($fh, $fname) = @_;
  518.     my $prefix = '';
  519.     my $typeflag = '0';
  520.     my $linkname;
  521.     my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  522. INTRO
  523.         \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
  524. SUB
  525.     local (*IN);
  526.  
  527.     if ($nlink > 1) {
  528.         if ($linkname = $linkseen{$fh, $dev, $ino}) {
  529.             if (length($linkname) > 100) {
  530.                 warn "$0: omitting file with linkname ",
  531.                      "too long for tar output: $linkname\n";
  532.                 return;
  533.             }
  534.             $typeflag = '1';
  535.             $size = 0;
  536.         } else {
  537.             $linkseen{$fh, $dev, $ino} = $fname;
  538.         }
  539.     }
  540.     if ($typeflag eq '0') {
  541.         if (-f _) {
  542.             open(IN, "./$_\0") || do {
  543.                 warn "Couldn't open $fname: $!\n";
  544.                 return;
  545.             }
  546.         } else {
  547.             $linkname = readlink($_);
  548.             if (defined $linkname) { $typeflag = '2' }
  549.             elsif (-c _) { $typeflag = '3' }
  550.             elsif (-b _) { $typeflag = '4' }
  551.             elsif (-d _) { $typeflag = '5' }
  552.             elsif (-p _) { $typeflag = '6' }
  553.         }
  554.     }
  555.  
  556.     if (length($fname) > 100) {
  557.         ($prefix, $fname) = ($fname =~ m#\A(.*?)/(.{,100})\Z(?!\n)#);
  558.         if (!defined($fname) || length($prefix) > 155) {
  559.             warn "$0: omitting file with name too long for tar output: ",
  560.                  $fname, "\n";
  561.             return;
  562.         }
  563.     }
  564.  
  565.     $size = 0 if $typeflag ne '0';
  566.     my $header = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155",
  567.                         $fname,
  568.                         sprintf("%7o ", $mode &    0777),
  569.                         sprintf("%7o ", $uid  & 0777777),
  570.                         sprintf("%7o ", $gid  & 0777777),
  571.                         sprintf("%11o ", $size),
  572.                         sprintf("%11o ", $mtime),
  573.                         ' 'x8,
  574.                         $typeflag,
  575.                         defined $linkname ? $linkname : '',
  576.                         "ustar\0",
  577.                         "00",
  578.                         $user{$uid},
  579.                         $group{$gid},
  580.                         ($rdev >> 8) & 0xff,
  581.                         $rdev & 0xff,
  582.                         $prefix,
  583.                      );
  584.     substr($header, 148, 8) = sprintf("%7o ", unpack("%16C*", $header));
  585.     my $l = length($header) % 512;
  586.     $tarout{$fh} .= $header;
  587.     $tarout{$fh} .= "\0" x (512 - $l) if $l;
  588.  
  589.     if ($size) {
  590.         flush($fh, \$tarout{$fh}, 10240)
  591.             while ($l = length($tarout{$fh})) >= 10240;
  592.         while (sysread(IN, $tarout{$fh}, 10240 - $l, $l)) {
  593.             my $slop = length($tarout{$fh}) % 512;
  594.             $tarout{$fh} .= "\0" x (512 - $slop) if $slop;
  595.             flush($fh, \$tarout{$fh}, 10240);
  596.             $l = length($tarout{$fh});
  597.         }
  598.         close IN;
  599.     }
  600. }
  601.  
  602. sub tflushall {
  603.     my $len;
  604.     for my $fh (keys %tarout) {
  605.         $len = 10240 - length($tarout{$fh});
  606.         $len += 10240 if $len < 1024;
  607.         $tarout{$fh} .= "\0" x $len;
  608.         flush($fh, \$tarout{$fh}, 10240);
  609.     }
  610. }
  611.  
  612. END
  613. }
  614.  
  615. exit;
  616.  
  617. ############################################################################
  618.  
  619. sub tab {
  620.     my $tabstring;
  621.  
  622.     $tabstring = "\t" x ($indent_depth/2) . ' ' x ($indent_depth%2 * 4);
  623.     if (!$statdone) {
  624.         if ($_ =~ /^(?:name|print|prune|exec|ok|\(|\))/) {
  625.             $init{delayedstat} = 1;
  626.         } else {
  627.             my $statcall = '(($dev,$ino,$mode,$nlink,$uid,$gid) = '
  628.                          . $stat . '($_))';
  629.             if (exists $init{saw_or}) {
  630.                 $tabstring .= "(\$nlink || $statcall) &&\n" . $tabstring;
  631.             } else {
  632.                 $tabstring .= "$statcall &&\n" . $tabstring;
  633.             }
  634.             $statdone = 1;
  635.             $init{declarestat} = 1;
  636.         }
  637.     }
  638.     $tabstring =~ s/^\s+/ / if $out =~ /!$/;
  639.     $tabstring;
  640. }
  641.  
  642. sub fileglob_to_re {
  643.     my $x = shift;
  644.     $x =~ s#([./^\$()])#\\$1#g;
  645.     $x =~ s#([?*])#.$1#g;
  646.     "^$x\\z";
  647. }
  648.  
  649. sub n {
  650.     my ($pre, $n) = @_;
  651.     $n =~ s/^-/< / || $n =~ s/^\+/> / || $n =~ s/^/== /;
  652.     $n =~ s/ 0*(\d)/ $1/;
  653.     "($pre $n)";
  654. }
  655.  
  656. sub quote {
  657.     my $string = shift;
  658.     $string =~ s/\\/\\\\/g;
  659.     $string =~ s/'/\\'/g;
  660.     "'$string'";
  661. }
  662.  
  663. __END__
  664.  
  665. =head1 NAME
  666.  
  667. find2perl - translate find command lines to Perl code
  668.  
  669. =head1 SYNOPSIS
  670.  
  671.     find2perl [paths] [predicates] | perl
  672.  
  673. =head1 DESCRIPTION
  674.  
  675. find2perl is a little translator to convert find command lines to
  676. equivalent Perl code.  The resulting code is typically faster than
  677. running find itself.
  678.  
  679. "paths" are a set of paths where find2perl will start its searches and
  680. "predicates" are taken from the following list.
  681.  
  682. =over 4
  683.  
  684. =item C<! PREDICATE>
  685.  
  686. Negate the sense of the following predicate.  The C<!> must be passed as
  687. a distinct argument, so it may need to be surrounded by whitespace and/or
  688. quoted from interpretation by the shell using a backslash (just as with
  689. using C<find(1)>).
  690.  
  691. =item C<( PREDICATES )>
  692.  
  693. Group the given PREDICATES.  The parentheses must be passed as distinct
  694. arguments, so they may need to be surrounded by whitespace and/or
  695. quoted from interpretation by the shell using a backslash (just as with
  696. using C<find(1)>).
  697.  
  698. =item C<PREDICATE1 PREDICATE2>
  699.  
  700. True if _both_ PREDICATE1 and PREDICATE2 are true; PREDICATE2 is not
  701. evaluated if PREDICATE1 is false.
  702.  
  703. =item C<PREDICATE1 -o PREDICATE2>
  704.  
  705. True if either one of PREDICATE1 or PREDICATE2 is true; PREDICATE2 is
  706. not evaluated if PREDICATE1 is true.
  707.  
  708. =item C<-follow>
  709.  
  710. Follow (dereference) symlinks.  The checking of file attributes depends
  711. on the position of the C<-follow> option. If it precedes the file
  712. check option, an C<stat> is done which means the file check applies to the
  713. file the symbolic link is pointing to. If C<-follow> option follows the
  714. file check option, this now applies to the symbolic link itself, i.e.
  715. an C<lstat> is done.
  716.  
  717. =item C<-depth>
  718.  
  719. Change directory traversal algorithm from breadth-first to depth-first.
  720.  
  721. =item C<-prune>
  722.  
  723. Do not descend into the directory currently matched.
  724.  
  725. =item C<-xdev>
  726.  
  727. Do not traverse mount points (prunes search at mount-point directories).
  728.  
  729. =item C<-name GLOB>
  730.  
  731. File name matches specified GLOB wildcard pattern.  GLOB may need to be
  732. quoted to avoid interpretation by the shell (just as with using
  733. C<find(1)>).
  734.  
  735. =item C<-perm PERM>
  736.  
  737. Low-order 9 bits of permission match octal value PERM.
  738.  
  739. =item C<-perm -PERM>
  740.  
  741. The bits specified in PERM are all set in file's permissions.
  742.  
  743. =item C<-type X>
  744.  
  745. The file's type matches perl's C<-X> operator.
  746.  
  747. =item C<-fstype TYPE>
  748.  
  749. Filesystem of current path is of type TYPE (only NFS/non-NFS distinction
  750. is implemented).
  751.  
  752. =item C<-user USER>
  753.  
  754. True if USER is owner of file.
  755.  
  756. =item C<-group GROUP>
  757.  
  758. True if file's group is GROUP.
  759.  
  760. =item C<-nouser>
  761.  
  762. True if file's owner is not in password database.
  763.  
  764. =item C<-nogroup>
  765.  
  766. True if file's group is not in group database.
  767.  
  768. =item C<-inum INUM>
  769.  
  770. True file's inode number is INUM.
  771.  
  772. =item C<-links N>
  773.  
  774. True if (hard) link count of file matches N (see below).
  775.  
  776. =item C<-size N>
  777.  
  778. True if file's size matches N (see below) N is normally counted in
  779. 512-byte blocks, but a suffix of "c" specifies that size should be
  780. counted in characters (bytes) and a suffix of "k" specifes that
  781. size should be counted in 1024-byte blocks.
  782.  
  783. =item C<-atime N>
  784.  
  785. True if last-access time of file matches N (measured in days) (see
  786. below).
  787.  
  788. =item C<-ctime N>
  789.  
  790. True if last-changed time of file's inode matches N (measured in days,
  791. see below).
  792.  
  793. =item C<-mtime N>
  794.  
  795. True if last-modified time of file matches N (measured in days, see below).
  796.  
  797. =item C<-newer FILE>
  798.  
  799. True if last-modified time of file matches N.
  800.  
  801. =item C<-print>
  802.  
  803. Print out path of file (always true).
  804.  
  805. =item C<-print0>
  806.  
  807. Like -print, but terminates with \0 instead of \n.
  808.  
  809. =item C<-exec OPTIONS ;>
  810.  
  811. exec() the arguments in OPTIONS in a subprocess; any occurence of {} in
  812. OPTIONS will first be substituted with the path of the current
  813. file.  Note that the command "rm" has been special-cased to use perl's
  814. unlink() function instead (as an optimization).  The C<;> must be passed as
  815. a distinct argument, so it may need to be surrounded by whitespace and/or
  816. quoted from interpretation by the shell using a backslash (just as with
  817. using C<find(1)>).
  818.  
  819. =item C<-ok OPTIONS ;>
  820.  
  821. Like -exec, but first prompts user; if user's response does not begin
  822. with a y, skip the exec.  The C<;> must be passed as
  823. a distinct argument, so it may need to be surrounded by whitespace and/or
  824. quoted from interpretation by the shell using a backslash (just as with
  825. using C<find(1)>).
  826.  
  827. =item C<-eval EXPR>
  828.  
  829. Has the perl script eval() the EXPR.  
  830.  
  831. =item C<-ls>
  832.  
  833. Simulates C<-exec ls -dils {} ;>
  834.  
  835. =item C<-tar FILE>
  836.  
  837. Adds current output to tar-format FILE.
  838.  
  839. =item C<-cpio FILE>
  840.  
  841. Adds current output to old-style cpio-format FILE.
  842.  
  843. =item C<-ncpio FILE>
  844.  
  845. Adds current output to "new"-style cpio-format FILE.
  846.  
  847. =back
  848.  
  849. Predicates which take a numeric argument N can come in three forms:
  850.  
  851.    * N is prefixed with a +: match values greater than N
  852.    * N is prefixed with a -: match values less than N
  853.    * N is not prefixed with either + or -: match only values equal to N
  854.  
  855. =head1 SEE ALSO
  856.  
  857. find
  858.  
  859. =cut
  860.  
  861. __END__
  862. :endofperl
  863.